package com.itheima.controller;

import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;
import java.util.List;

@RestController
public class HelloController   {

    @Autowired
    private DataSource dataSource;
    @Autowired
    private UserService userService;
//    @Value("${itcast.url}")
//    private String itcastUrl;
//    @Value("${itheima.url}")
//    private String itheimaUrl;

    @GetMapping("hello")
    public String hello(){
        System.out.println("datas="+dataSource);
        return "hello,spring boot";
    }
    @GetMapping("/user")
    public List<User> findAll(){
        return userService.findAll();
    }
    @GetMapping("/user/{id}")
    public User findById(@PathVariable long id){
       return userService.findById(id);
    }
    @GetMapping("/user/add")
    public void add(@PathVariable User user){
       user.setUserName("kebi");
        userService.add(user);
    }
    @GetMapping("/user/deleteById/{id}")
    public void deleteById(@PathVariable long id){
        userService.deleteById(id);
    }
    @GetMapping("/user/update/{id}")
    public void update(@PathVariable User user){
        User user1 = userService.findById(14L);
        user1.setUserName("musi222");
        userService.update(user1);
    }
}
